package com.swsc.ai.config;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

/**
 * @author QF
 * @date 2023/10/10 15:03
 * @describe
 */
public class SparkRDDConf {

    public static JavaRDD<String> readRDD(String appName, String inPath){
        // 创建SparkConf对象
        SparkConf conf = new SparkConf()
                .setAppName(appName)
                .setMaster("yarn");
        // 创建JavaSparkContext对象
        JavaSparkContext sc = new JavaSparkContext(conf);
        try {
            // 读取文本文件
            return sc.textFile(inPath);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (null != sc){
                sc.close();
            }
        }
       return null;
    }
}
